package com.glela.serial.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.glela.serial.mapper.TalentSerialContentMapper;
import com.glela.serial.mapper.TalentSerialEditAndShareMapper;
import com.glela.serial.mapper.TalentSerialGoodsMapper;
import com.glela.serial.mapper.TalentSerialMapper;
import com.glela.serial.model.TalentSerial;
import com.glela.serial.model.TalentSerialContent;
import com.glela.serial.model.response.ResponseTalentSerialContentVo;
import com.glela.serial.model.response.ResponseTalentSerialVo;
import com.glela.serial.service.TalentSerialService;
@Service("talentSerialService")
public class TalentSerialServiceImpl implements TalentSerialService{

	@Autowired
	private TalentSerialMapper talentSerialMapper;
	@Autowired
	private TalentSerialGoodsMapper talentSerialGoodsMapper;
	@Autowired
	private TalentSerialEditAndShareMapper talentSerialEditAndShareMapper;
	@Autowired
	private TalentSerialContentMapper talentSerialContentMapper;
	//生成空的达人期
	@Override
	public ResponseTalentSerialVo addTalentSerial(long TalentId) {
		ResponseTalentSerialVo responseTalentSerialVo=new ResponseTalentSerialVo();
		// TODO Auto-generated method stub
		talentSerialMapper.insertTalentSerial(TalentId);
		TalentSerial talentSerial=talentSerialMapper.selectTalentSerialDesc(TalentId);
		responseTalentSerialVo.setTalentSerialId(talentSerial.getId());
		return responseTalentSerialVo;
	}
	//添加达人期内商品
	@Override
	public int addTalentSerialGoods(long talentSerialId, long goodId) {
		// TODO Auto-generated method stub
		int i=talentSerialGoodsMapper.insertTalentSerialGoods(talentSerialId, goodId);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	@Override
	public int removeTalentSerial(long talentSerialId, long talentId) {
		// TODO Auto-generated method stub
		int i=talentSerialMapper.deleteTalentSerial(talentSerialId, talentId);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	@Override
	public int removeTalentSerialGoods(long talentSerialId, long goodId) {
		// TODO Auto-generated method stub
		int i =talentSerialGoodsMapper.deleteTalentSerialGoods(talentSerialId, goodId);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	@Override
	public int changeTalentSerialImagePath(long talentSerialId, String imagePath) {
		// TODO Auto-generated method stub
		int i=talentSerialMapper.updateTalentSerialImagePath(talentSerialId, imagePath);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}

	public int updateTalentSerialLabelName(long talentSerialId, String labelName) {
		// TODO Auto-generated method stub
		int i =talentSerialMapper.updateTalentSerialLabelName(talentSerialId, labelName);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	
	@Override
	public int updateTalentSerialLaTitle(long talentSerialId, String title) {
		// TODO Auto-generated method stub
		int i =talentSerialMapper.updateTalentSerialLaTitle(talentSerialId, title);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	@Override
	public int addTalentSerialEditAndShare(long talentId, long talentSerialId,String title) {
		// TODO Auto-generated method stub
		int i=talentSerialEditAndShareMapper.insertTalentSerialEditAndShare(talentId, talentSerialId);
		if (i<=0) {
			i=0;
			return i;
		}
		if (title!=null) {
			talentSerialMapper.updateTalentSerialLaTitle(talentSerialId, title);
		}
		return i;
	}
	@Override
	public int addTalentSerialCtntent(long talentSerialId, List<String> imagePath,int imgWidth,int imgHeight) {
		// TODO Auto-generated method stub
		for (String imgage:imagePath) {
			talentSerialContentMapper.insertTalentSerialCtntent(talentSerialId, imgage,imgWidth,imgHeight);
		}
		int i=imagePath.size();
		return i;
	}
	
	
	@Override
	public int removeTalentSerialontent(long talentSerialId, long talentSerialontentId) {
		// TODO Auto-generated method stub
		int i =talentSerialContentMapper.deleteTalentSerialontent(talentSerialId, talentSerialontentId);
		if (i<=0) {
			i=0;
			return i;
		}
		return i;
	}
	@Override
	public List<ResponseTalentSerialContentVo> listTalentSerialContentImgPath(long talentSerialId) {
		// TODO Auto-generated method stub
		List<ResponseTalentSerialContentVo> list=new ArrayList<ResponseTalentSerialContentVo>();
		List<TalentSerialContent> aa=talentSerialContentMapper.selectTalentSerialContentImgPath(talentSerialId);
		for (TalentSerialContent talentSerialContent:aa) {
			ResponseTalentSerialContentVo cc=new ResponseTalentSerialContentVo();
			cc.setTalentSerialContentId(talentSerialContent.getId());
			cc.setImgpath(talentSerialContent.getImagePath());
			list.add(cc);
		}
		return list;
	}

	
}
